/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package di.persistence.object.impl;

import di.persistence.dao.UserDao;
import di.persistence.dao.UserTypeDao;
import di.persistence.entities.User;
import di.persistence.entities.UserType;
import di.persistence.object.UserBO;
import java.util.List;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 * @author Kilian Ito
 */

@Service("UserBO")
public class UserBOImpl implements UserBO{

    @Autowired
    UserDao userDao;
    @Autowired
    UserTypeDao userTypeDao;
    
    private Logger logger = Logger.getLogger(UserBO.class);
    
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    @Override
    public void save(User user) {
        userDao.save(user);
    }

    @Override
    public void update(User user) {
        userDao.update(user);
    }

    @Override
    public void delete(User user) {
        userDao.delete(user);
    }

    @Override
    public User getUser(long id) {
        User ret = userDao.getUser(id);
        if (ret == null)
            logger.log(Level.WARN, "No User found for ID '"+id+"'");
        return ret;
    }

    @Override
    public User getUserByLogin(String login) {
        User ret = userDao.getUserByLogin(login);
        if (ret == null)
            logger.log(Level.WARN, "No User found for login '"+login+"'");
        return ret;
    }

    @Override
    public User getUserByEmail(String email) {
        User ret = userDao.getUserByEmail(email);
        if (ret == null)
            logger.log(Level.WARN, "No User found for login '"+email+"'");
        return ret;
    }

    @Override
    public List<UserType> getTypes(User user) {
        return userDao.getTypes(user);
    }
    
}
